<%@ page language="java" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>Unibase - 用户登录</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="Heat">
	<meta http-equiv="description" content="Heat">
	
	<!-- css -->
	<link rel="stylesheet" type="text/css" href="<%=path%>/resources/js/extjs/resources/css/ext-all-neptune.css">
	<link rel="stylesheet" type="text/css" href="<%=path%>/resources/css/icon.css"/>
	
	<!-- js -->
	<script type="text/javascript" src="<%=path%>/resources/js/extjs/ext-all.js"></script>
	<script type="text/javascript" src="<%=path%>/resources/js/extjs/locale/ext-lang-zh_CN.js"></script>
	<script type="text/javascript">
  		Ext.require([
        	'Ext.form.*'
       	]);

       	Ext.onReady(function(){

  	       	Ext.QuickTips.init();
  	       	
  	       	var form = Ext.create('Ext.form.Panel',{
  	       		layout:'absolute',
  	       		renderTo:'loginForm',//渲染到页面中的loginForm层中	
  	       		draggable:false,	 //是否可以拖动		
  	       		buttonAlign:'center',//使buttons中的button居中显示
  	       						
  	       		items:[
  	       			{
  	       				x:40,
  	       				y:23,
  	       				xtype:'label',
  	       				text:'用户名：',
  	       				style:'color:#0033FF; font-size: 9pt;font-weight:bold'
  	       			},
  	       	       	{
  	       	       	   x:90,
  	       	       	   y:20,
  	       	    	   xtype:'textfield',
  	       	    	   name:'logName',
  	       	    	   //不允许为空
  	       	    	   allowBlank:false,
  	       	    	   blankText:'用户名不能为空',
  	       	    	   width:140
  	       	       	},
  	       	       	{
  	       	       		x:40,
  	       	       		y:56,
  	       	       		xtype:'label',
  	       	       		text:'密',
  	       	       		style:'color:#0033FF; font-size: 9pt;font-weight:bold'
  	       	       	},
  	       	       	{
  	       	       		x:64,
  	       	       		y:56,
  	       	       		xtype:'label',
  	       	       		text:'码：',
  	       	       		style:'color:#0033FF; font-size: 9pt;font-weight:bold'
  	       	       	},
  	       	       	{
  	       	       	   x:90,
  	       	       	   y:53,
  	       	    	   xtype:'textfield',
  	       	    	   name:'password',
  	       	    	   inputType:'password',
  	       	    	   allowBlank:false,
  	       	    	   blankText:'密码不能为空',
  	       	    	   width:140
  	       	       	}
  	       		],
  	       		buttons:[
  	               	{
  	               	 	text:'登录',
  	               	 	iconCls:'icon-loginIcon',
  	               	 	width:70,
  	               	 	height:25,
  	               	 	handler: login
  	               	},
  	       			{
  	               	 	text:'重置',
  	               	 	iconCls:'icon-resetIcon',
  	               	 	width:70,
  	               	 	height:25,
  	       	        	 
  	               	 	handler:function(){	       		 	
  	       	       		 	this.up('form').getForm().reset();//点击取消，关闭登录窗口
  	       					//this.up('window').hide();
  	       			 	}
  	       			}
  	       		],
				listeners: {
		            afterRender: function(thisForm, options){
		                this.keyNav = Ext.create('Ext.util.KeyNav', this.el, {
		                    enter: login,
		                    scope: this
		                });
		            }
				}
  	       	});
  	       	
  	       	
  	       	function login(){
      		 	//var form1 = form.getForm();//获取当前的表单form
      			
      		 	if(form.isValid()){//判断否通过了表单验证，如果不能空的为空则不能提交
     			 	//alert("可以提交");
      			 	form.submit(
   					 	{
   						 	clientValidation:true,
      						waitMsg:'请稍候',
      						waitTitle:'正在验证登录',
      						url:'user/userLogin',
      						
   						 	success:function(form,action){
   							 	//登录成功后的操作，这里只是提示一下
   							 	Ext.MessageBox.show({
                              	width:150,					//窗体宽度
                                   title:"登录成功",				//提示信息
                                   buttons: Ext.MessageBox.OK,	//确定按钮
                                   icon :Ext.MessageBox.INFO,  //成功的图标
                                   msg:action.result.text      //登录成功消息
                           		});
                                   
                                window.location.href = "user/index";                                                                         	
   						 	},
   						 	failure:function(form,action){
   							 	Ext.MessageBox.show({
                                    width:150,					 //窗体宽度
                                    title:"登录失败",				 //提示信息
                                    buttons: Ext.MessageBox.OK,  //确定按钮                                 
                                    icon :Ext.MessageBox.ERROR,  //失败的图标
                                    msg:action.result.text       //登录失败消息
                       			});
      						 }    					 		
      					 }
      			 	);
      		 	}
  	       	}
  	       			
  	       	//窗体
           	var win = Ext.widget('window', {
	        	title: '用户信息',
               	iconCls:'icon-user',
               	closeAction: 'hide',
               	width: 300,
               	height: 170,
  	            minHeight: 170,
  	            layout: 'fit',	 
  	            resizable: true,
  	            modal: true,
  	            items: form,   
  	            closable:false
           	});
  	           
           	win.show();
		});
  	</script>
  </head>
  
  <body>	
  	<div id="loginForm" align="center"></div>
  </body>
</html>
